package com.lf125.plus.plugin.LF125PlusPlugin;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

public class LFTagReadHelper {
    private Context context;
    private LF125KTagReadThread lf125KTagReadThread = new LF125KTagReadThread();
    private MessageCallBack mMsgCall;

    public void setContext(Context context) {
        this.context = context;
    }

    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == LF125KTagReadThread.MSG_RESULT) {
                long id = msg.getData().getLong("id");
                int country = msg.getData().getInt("country");
                Log.e("LFTagReaderManager", "id = " + id + "; country = " + country);
                if (mMsgCall != null) {
                    mMsgCall.onTagRead(id, country);
                }
            }
        }
    };

    public void setMessageCallback(MessageCallBack messageCallback) {
        this.mMsgCall = messageCallback;
    }

    public void initRead() {
        lf125KTagReadThread.setHandler(handler);
        lf125KTagReadThread.init();
    }

    public void startRead() {
        lf125KTagReadThread.startRead();
    }

    public void stopRead() {
        lf125KTagReadThread.stopRead();
    }

    public void close() {
        lf125KTagReadThread.close();
    }
}
